//
//  NetBusinessUser_GetUserList.m
//  EpointFrame5
//
//  Created by wangzhigang on 14-12-16.
//  Copyright (c) 2014年 Epoint. All rights reserved.
//

#import "NetBusinessUser_GetUserList.h"
#import "UserInfoModel.h"

@implementation NetBusinessUser_GetUserList
-(void)execute
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *ValidateData = [EpointBizTools getToken];
    NSString *url = self.getMobileOAWebserviceURL;
    NSString *wsNamespace = NSLocalizedString(@"Epoint_DNet_WS_NameSpace", @"");
    NSString *userguid = [params objectForKey:@"OwnerUserGuid"];
    NSString *ParentCategoryGuid = [params objectForKey:@"ParentCategoryGuid"];
    NSString *KeyWord = [params objectForKey:@"KeyWord"];
    
    NSString *ParasXml = @"<![CDATA[<?xml version=\"1.0\" encoding=\"gb2312\"?><paras><OwnerUserGuid>%@</OwnerUserGuid><ParentCategoryGuid>%@</ParentCategoryGuid><KeyWord>%@</KeyWord></paras>]]>";
    ParasXml = [NSString stringWithFormat:ParasXml,userguid,ParentCategoryGuid,KeyWord];
    EpointWebServiceUtil *ws = [[EpointWebServiceUtil alloc]initWithUrl:url namespace:wsNamespace method:@"NetBusinessUser_GetUserList"];
    [ws addParameterForString:@"ValidateData" value:ValidateData];
    [ws addParameterForString:@"ParasXml" value:ParasXml];
    NSString *bs =  ws.start;
    if ([self validateXMLWS:bs]) {
        [self exeSuccessWithData:[self getList:bs]];
    }
}
-(NSMutableArray*)getList:(NSString*)_xml{
    NSString *xmldata = [EpointStringUtil getXMLFormatedAttributeBsWithTag:_xml xmlTag:@"UserList"];
    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithXMLString:xmldata  options:0 error:nil];
    GDataXMLElement *rootElement = [doc rootElement];
    NSArray *arrays = [rootElement elementsForName:@"UserInfo"];
    NSMutableArray *listmp = [[NSMutableArray alloc]init];
    
    for (GDataXMLElement *arr in arrays)
    {
        UserInfoModel *m = [[UserInfoModel alloc]init];
        GDataXMLElement *UserGuid = [[arr elementsForName:@"UserGuid"] objectAtIndex:0];
        m.UserGuid = [UserGuid stringValue];
        
        GDataXMLElement *DisplayName = [[arr elementsForName:@"DisplayName"] objectAtIndex:0];
        m.DisplayName = [DisplayName stringValue];
        
        GDataXMLElement *CategoryGuid = [[arr elementsForName:@"CategoryGuid"] objectAtIndex:0];
        m.CategoryGuid = [CategoryGuid stringValue];
        
        GDataXMLElement *OrderNumber = [[arr elementsForName:@"OrderNumber"] objectAtIndex:0];
        m.OrderNumber = [OrderNumber stringValue];
        
        GDataXMLElement *Title = [[arr elementsForName:@"Title"] objectAtIndex:0];
        m.Title = [Title stringValue];
        
        GDataXMLElement *TelephoneOffice = [[arr elementsForName:@"TelephoneOffice"] objectAtIndex:0];
        m.TelephoneOffice = [TelephoneOffice stringValue];
        
        GDataXMLElement *TelephoneHome = [[arr elementsForName:@"TelephoneHome"] objectAtIndex:0];
        m.TelephoneHome = [TelephoneHome stringValue];
        
        GDataXMLElement *Mobile = [[arr elementsForName:@"Mobile"] objectAtIndex:0];
        m.Mobile = [Mobile stringValue];
        
        GDataXMLElement *Email = [[arr elementsForName:@"Email"] objectAtIndex:0];
        m.Email = [Email stringValue];
        
        GDataXMLElement *Sex = [[arr elementsForName:@"Sex"] objectAtIndex:0];
        m.Sex = [Sex stringValue];
        
        GDataXMLElement *Fax = [[arr elementsForName:@"Fax"] objectAtIndex:0];
        m.Fax = [Fax stringValue];
        m.type=@"user";
        [listmp addObject:m];
    }
    return listmp;
}

@end
